Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(switch): loading state can't be controlled with truthy initial state #3285

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

Cnotech
Copy link
Contributor

@Cnotech Cnotech commented Aug 29, 2024

Types of changes

  • New feature
  • Bug fix
  • Enhancement
  • Component style change
  • Typescript definition change
  • Documentation change
  • Coding style change
  • Refactoring
  • Test cases
  • Continuous integration
  • Breaking change
  • Others

Background and context

如果给 Switch 组件的 loading 传入初始状态为 true 的 Ref,内部的 _loading 会被初始化为 true,此时如果外部的 loading 变回 false 则 Switch 组件仍会处于 loading 状态,导致组件的 loading 态不受控。

If you pass a Ref to the loading of the Switch component with an initial state of true, the internal ref _loading will be initialized with true, then if the external loading ref changed to false, the Switch component will still be in the loading state, resulting in an uncontrolled loading state.

// script
const loading = ref(true);

// template
<a-button @click="loading = !loading">{{ loading }}</a-button>
<a-switch :loading="loading" />

20240829192136_rec_

Solution

How is the change tested?

20240829192738_rec_

Changelog

Component Changelog(CN) Changelog(EN) Related issues
Select fix(switch): 修复当加载状态被真值初始化后无法受控 fix(switch): loading state can't be controlled with truthy initial state

Checklist:

  • Test suite passes (npm run test)
  • Provide changelog for relevant changes (e.g. bug fixes and new features) if applicable.
  • Changes are submitted to the appropriate branch (e.g. features should be submitted to feature branch and others
    should be submitted to main branch)

Other information

Copy link

codesandbox bot commented Aug 29, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@oljc oljc added the 🐛 Bug Something isn't working label Sep 12, 2024
@oljc oljc merged commit faa5e93 into arco-design:main Sep 12, 2024
2 of 4 checks passed
@flsion flsion added this to the 2.56.2 milestone Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants